<?php	namespace Admin\Controller;
/**
 * 后台首页管理控制器
 * @author 武斌   <wubin.mail@foxmail.com>
 * @Date 
 */
class IndexController extends CommonController 
{
	//首页
	public function index()
	{
		if(IS_POST)
		{
			//1.post提交的班级名称
			$cname = $_POST['cname'];
			//2.写入数据库,这里注意$cname字段字符串类型，注意要加引号
			M()->exec("insert into class set cname='{$cname}'");
			//3.成功提示,这里调用的是controller.php里面的success方法
			$this->success("班级添加成功","index.php?m=Admin");exit;
		}
		//分配公共头部title数据
		$this->assign("title","班级管理首页");
		//获取数据库数据
		$data = M()->query("select * from class order by cid desc");
		//数据分配
		$this->assign("data",$data);
		//显示模板
		$this->display();
	}
	//编辑
	public function edit()
	{
		if(IS_POST)
		{
			//1.接受post提交参数
			$cid = $_POST['cid'];
			$cname = $_POST['cname'];
			//2.执行修改
			M()->exec("update class set cname='{$cname}' where cid={$cid}");
			//3.成功提示
			$this->success("班级修改成功","index.php?m=Admin");exit;
		}
		$this->error("非法请求","index.php?m=Admin");
	}
	//删除
	public function del()
	{
		if(IS_POST)
		{
			$cid = $_POST['cid'];
			M()->exec("delete from class where cid={$cid}");
			//3.成功提示
			$this->success("班级删除成功","index.php?m=Admin");exit;
		}
		$this->error("非法请求","index.php?m=Admin");
	}
}
 
 
 
